/*
 * Problem: 池子的数量（Lake Counting）
 * Author: Yuanshun L
 * Created: 8-Dec-2021
 * Topic: DFS
 */
#include<iostream>
#include<cstdio>

using namespace std;

const int maxn = 100+2;
char lake[maxn][maxn];

int dx[] = {-1,-1,-1,0,0,1,1,1};
int dy[] = {-1,0,1,-1,1,-1,0,1};

int n,m;

// 将一个池子填满成陆地
void dfs(int x,int y){
    int cx,cy;
    lake[x][y] = '.';

    for(int i=0;i<8;i++){
        cx = x + dx[i];
        cy = y + dy[i];
        // 超出边界
        if(cx < 0 || cy <0 || cx >= n || cy > m) continue;
        if(lake[cx][cy] == '.') continue;

        dfs(cx,cy);
    }
}

int solve(){
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(lake[i][j] == 'W'){
                ans++;
                dfs(i,j);
            }
        }
    }
    return ans;
}


int main(){
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);

    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> lake[i];
    }

    cout << solve() << endl;


    return 0;
}
